﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

public partial class Visitor_CalculateCharge : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
        
    }
    protected void imgbCheck_Click(object sender, ImageClickEventArgs e)
    {
        string dtype = ddlDType.SelectedItem.ToString();
        string item = ddlMType.SelectedItem.ToString();
        string weight = txtWeight.Text;
        string distance = ddlDistance.SelectedItem.ToString();
        
        int WID;
        string charge = "";
        if (float.Parse(weight) <= 50)
        {
            WID = 1;
        }
        else
            if (float.Parse(weight) >= 51 && float.Parse(weight) <= 200)
            {
                WID = 2;
            }
            else
                if (float.Parse(weight) >= 201 && float.Parse(weight) <= 500)
                {
                    WID = 3;
                }
                else
                    WID = 4;
        

        SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["OPOConnectionString"].ToString());
        cnn.Open();
        SqlCommand cmd = new SqlCommand("Select WeightCharge from WeightOfMail where WeightID= '" + WID + "'", cnn);
        SqlDataReader dread = cmd.ExecuteReader();
        if (dread.Read())
        {
            charge = dread.GetValue(0).ToString();
        }
        string total =Convert.ToString((float.Parse(ddlDType.SelectedValue) + float.Parse(charge)) * float.Parse(ddlDistance.SelectedValue));

        Response.Redirect("TotalPaid.aspx?DT=" + dtype + "&MT=" + item + "&W=" + charge + "&D=" + distance + "&T=" + total);
    }

    protected void imgbReset_Click(object sender, ImageClickEventArgs e)
    {
        ddlDType.SelectedIndex = 0;
        ddlMType.SelectedIndex = 0;
        ddlDistance.SelectedIndex = 0;
        txtWeight.Text = "";
    }
}